use std::result::Result;
use yaml_rust::{YamlEmitter, YamlLoader};

type YamlErrorCode = i32;

#[derive(Debug)]
pub struct YamlError {
  code: YamlErrorCode,
}

pub fn yaml_demo() -> Result<(), YamlError> {
  let s = "
# from yaml-cpp example
- name: Ogre
  position: [0, 5, 0]
  powers:
    - name: Club
      damage: 10
    - name: Fist
      damage: 8
- name: Dragon
  position: [1, 0, 10]
  powers:
    - name: Fire Breath
      damage: 25
    - name: Claws
      damage: 15
- name: Wizard
  position: [5, -3, 0]
  powers:
    - name: Acid Rain
      damage: 50
    - name: Staff
      damage: 3
";
  let docs = YamlLoader::load_from_str(s).unwrap();
  let doc = &docs[0];

  assert_eq!(doc[0]["name"].as_str().unwrap(), "Ogre");

  let mut writer = String::new();
  {
    let mut emitter = YamlEmitter::new(&mut writer);
    emitter.dump(doc).unwrap();
  }

  assert!(!writer.is_empty());
  Ok(())
}
